package course.service.impl;

import course.dao.TeaSubDao;
import course.dao.impl.TeaSubDaoImpl;
import course.pojo.entity.TeaSub;
import course.service.TeaSubService;
import course.utils.JDBCUtil;

import java.sql.Connection;
import java.util.List;

/**
 * @author HLF
 * @date 2022/7/3 9:50
 */
public class TeaSubServiceImpl implements TeaSubService {
    private TeaSubDao teaSubDao = new TeaSubDaoImpl();

    @Override
    public int addTeaSub(TeaSub teaSub) {
        Connection connection = JDBCUtil.getConnection();
        int i = teaSubDao.addTeaSub(teaSub, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public List<TeaSub> getList() {
        Connection connection = JDBCUtil.getConnection();
        List<TeaSub> list = teaSubDao.getList(connection);
        JDBCUtil.closeConnection(connection);
        return list;
    }

    @Override
    public List<TeaSub> getByTid(Integer tid) {
        Connection connection = JDBCUtil.getConnection();
        List<TeaSub> bySid = teaSubDao.getByTid(tid, connection);
        JDBCUtil.closeConnection(connection);
        return bySid;
    }

    @Override
    public List<TeaSub> getBySuid(Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        List<TeaSub> bySuid = teaSubDao.getBySuid(suid, connection);
        JDBCUtil.closeConnection(connection);
        return bySuid;
    }

    @Override
    public TeaSub getByTidAndSuid(Integer tid, Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        TeaSub teaSub = teaSubDao.getByTidAndSuid(tid, suid, connection);
        JDBCUtil.closeConnection(connection);
        return teaSub;
    }

    @Override
    public int deleteByTidAndSuid(Integer tid, Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        int i = teaSubDao.deleteByTidAndSuid(tid, suid, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public int deleteSelect(List<Integer> ids, Integer tid) {
        Connection connection = JDBCUtil.getConnection();
        int i = teaSubDao.deleteSelect(ids, tid, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }
}
